package com.sunshine.wrongquestionset.activity.exercise

import android.annotation.SuppressLint
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.sunshine.wrongquestionset.R
import kotlinx.android.synthetic.main.fragment_exercise_info.*
import java.text.SimpleDateFormat
import java.util.*

class ExerciseInfoFragment : Fragment() {

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.fragment_exercise_info, container, false)
    }

    @SuppressLint("SetTextI18n", "SimpleDateFormat")
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm")
        textView_question_name.text = "${ExerciseActivity.subjectName}测试题"
        textView_question_info.text = "科目：${ExerciseActivity.subjectName}\n时间：${simpleDateFormat.format(Date())}\n总分：${getSumScore()}分\n题目数量：${ExerciseActivity.getQuestionList()?.size?:0}道"
    }

    private fun getSumScore(): Float {
        var sum = 0.0f
        ExerciseActivity.getQuestionList()?.forEach {
            sum += it.score
        }
        return sum
    }
}